package mh.map;

import java.util.ArrayList;

import mh.SpellEntity;

/**
 * The layer that contains each spell that is cast in this map.
 * 
 * @author Gianmarco Laggia
 */
public class SpellsLayer extends Layer {

	/**
	 * The list of the entities in this layer
	 */
	private ArrayList<SpellEntity>	spells;

	/**
	 * @param x
	 *            Player's X position in the map.
	 * @param y
	 *            Player's Y position in the map
	 */
	public SpellsLayer(double x, double y) {
		super(x, y, 0, 0);
		this.spells = new ArrayList<SpellEntity>();
		this.frameDuration = VELOCITY / 4;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mh.Layer#draw(double)
	 */
	@Override
	public void draw(long delta) {
		for (int i = 0; i < this.spells.size(); i++) {
			SpellEntity spell = this.spells.get(i);
			spell.setPlayerCoord(this.actualx, this.actualy);
			spell.draw(delta);
		}

		this.lastFrameChange += delta;
		if (this.lastFrameChange > this.frameDuration) {
			this.lastFrameChange = 0;
			if (this.actualx < this.finalx) {
				this.actualx += 0.25;
			} else if (this.actualx > this.finalx) {
				this.actualx -= 0.25;
			} else if (this.actualy < this.finaly) {
				this.actualy += 0.25;
			} else if (this.actualy > this.finaly) {
				this.actualy -= 0.25;
			}
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see mh.Layer#isAvaible(int, int)
	 */
	@Override
	public boolean isAvaible(int x, int y) {
		return true;
	}

	/**
	 * Add a new entity to the list.
	 * 
	 * @param s
	 */
	public void addSpell(SpellEntity s) {
		this.spells.add(s);
	}

	/**
	 * Return the list of all the spells present and effective in this map.
	 * 
	 * @return The list of spells
	 */
	public ArrayList<SpellEntity> getSpells() {
		return this.spells;
	}

}
